<div class="modal-body">
	<form id="role-form" name="role-form" class="form-horizontal">
		<input type="hidden" name="id" id="roleId">
		<input type="hidden" name="create_time" data-flag="date" data-format="yyyy-MM-dd HH:mm:ss">
		<input type="hidden" name="deleted">
		<div class="box-body">
			<div class="col-md-12">
				<div class="form-group">
					<label for="name" class="col-sm-3 control-label">角色名称</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" id="name" name="name" placeholder="角色名称">
					</div>
				</div>
				<div class="form-group">
					<label for="code" class="col-sm-3 control-label">角色编码</label>
					<div class="col-sm-8">
						<input type="text" class="form-control" id="code" name="code" placeholder="角色编码">
					</div>
				</div>
				<div class="form-group">
					<label for="remark" class="col-sm-3 control-label">描述信息</label>
					<div class="col-sm-8">
						<textarea rows="5" class="form-control" id="remark" name="remark" placeholder="描述信息"/>
					</div>
				</div>
			</div>
		</div>
		<!-- /.box-body -->
		<div class="box-footer text-right">
			<!--以下两种方式提交验证,根据所需选择-->
			<button type="button" class="btn btn-default" data-btn-type="cancel" onclick="dialog_close()">取消</button>
			<button type="button" class="btn btn-primary" data-btn-type="save" onclick="save_role()">提交</button>
		</div>
		<!-- /.box-footer -->
	</form>
</div>
<script type="text/javascript">
	$(document).ready(function(){
		view_role()
	});
	
	function view_role(){
		//从datatable上获取已经选择的条目
		if( Dtable_roleInfo.rows('.selected').data().length > 0 ){
			var id = Dtable_roleInfo.rows('.selected').data()[0].id;
			$("#roleId").val( id );
			if( id == "null" ||id == null || id == undefined || id == "0" ){
				return false;
			}
			//说明是查询
			$("#id").val(id);
			var url = "../../tbl_role/" + id;
			$.getJSON(url, null, function(json){
				//向页面上加载信息
				if( json && json.data ){
					var role = json.data;
					$("#roleId").val(role.id);
					$("#name").val(role.name );
			 		$("#code").val(role.code);
			 		$("#remark").val(role.remark);
			 		$("#deleted").val(role.deleted);
			 		$("#create_time").val(role.create_time);
				}			
			});
		}
	}
	
	function save_role( fn ){
		var role = {};
		role.id = $("#roleId").val();
		role.code = $("#code").val();
		role.name = $("#name").val();
		role.remark = $("#remark").val();
		role.create_time = $("#create_time").val();
		role.deleted = $("#deleted").val();
		var json_data = JSON.stringify( role );
		var url = "../../tbl_role/save";
		$.ajax({
			  url: url,
			  type : 'post',
			  async : false,
			  data: json_data,
			  contentType: "application/json; charset=utf-8",
			  dataType: "json",
			  success: function(json) {
				 global.alert(json.message);
				 $("#system_main").load("um/um_rolelist.html");
				 dialog_close();
				 if(fn){fn();}
			  }
		});
	}
	
	function dialog_close(){
		global.dialog.close()
	}
</script>